<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------
namespace app\plat\model;

/**
 * 用户模型
 */
class TenUserPosition extends PlatBase
{
    /**
     * 获得职位下所有用户
     * @param $deptId
     * @param $type self, selfson, son
     * @return mixed
     * @author: 开发人生 goodkfrs@qq.com
     * @Time: 2025/3/9 17:07
     */
    public function getPositionAllUsers($positionId = 0, $type = 'self')
    {
        //获得部门下所有用户
        switch ($type) {
            case 'self':
                $positionIds = $positionId;
                break;
            case 'son':
                $positionIds = $this->modelTenPostion->getTenPositionAllSon();
                break;
            case 'selfson':
                $positionIds = $this->modelTenPostion->getTenPositionAllSon($positionId);
                $positionIds[] = $positionId;
                break;
        }
        $positionIds[] = $positionId;
        $this->modelTenUserPosition->alias('a');
        $this->modelTenUserPosition->join = [
            [SYS_DB_PREFIX . 'ten_user b', 'a.ten_position_id=b.id'],
        ];
        $where['a.ten_position_id'] = ['in', $positionIds];
        $userList = $this->modelTenUserPosition->getList($where, 'b.*', 'a.id desc', false)->toArray();
        return $userList;
    }
}
